/**
 * 
 */
package com.gi.profiler;

import android.content.Intent;
import android.media.RingtoneManager;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;

import com.gi.profiler.controllers.ProfileController;
import com.gi.profiler.listeners.ProfilePrefsListener;
import com.gi.profiler.model.Profile;
import com.gi.profiler.utils.DataConstants;
import com.gi.profiler.utils.Utility;

/**
 * @author Ruba
 * 
 */
public class ProfilePreferencesActivity extends PreferenceActivity {
    private Profile profile;

    private Preference volume;
    private EditTextPreference prefProfileName;
    private ProfilePrefsListener listener;
    private Preference iconPref;
    private Preference ringtone, notification;

    public void onCreate(Bundle savedInstance) {
	super.onCreate(savedInstance);
	 addPreferencesFromResource(R.xml.profile_prefs);
	 
	Integer profId = (Integer) getIntent().getIntExtra(DataConstants.PROFILE_ID_FOR_VIEW, -1);
	profile = new ProfileController().getFilledProfileById(profId);
	
	listener = new ProfilePrefsListener(this);

	prefProfileName = (EditTextPreference) findPreference(getString(R.string.key_prof_name));
	prefProfileName.setSummary(profile.getName());
	prefProfileName.setOnPreferenceChangeListener(listener);
	
	iconPref = (Preference)findPreference(getString(R.string.key_prof_icon));
	iconPref.setOnPreferenceChangeListener(listener);
//	iconPref.getView(iconPref, null);
//	iconPref.getV(Utility.getDrawableIdByName(profile.getIcon()));
	
	volume = (Preference) findPreference(getString(R.string.key_volume));
	volume.setOnPreferenceClickListener(listener);
	
	ringtone = (Preference) findPreference(getString(R.string.key_ringtone));
	ringtone.setOnPreferenceClickListener(listener);
//	ringtone.setEntries((CharSequence[])Utility.getAvailableTonesForSoundType(RingtoneManager.TYPE_RINGTONE));
//	ringtone.setEntryValues((CharSequence[])Utility.getAvailableTonesForSoundType(RingtoneManager.TYPE_RINGTONE));
		
	notification = (Preference) findPreference(getString(R.string.key_notif_sound));
	notification.setOnPreferenceClickListener(listener);
//	notification.setEntries((CharSequence[])Utility.getAvailableTonesForSoundType(RingtoneManager.TYPE_NOTIFICATION));
//	notification.setEntryValues((CharSequence[])Utility.getAvailableTonesForSoundType(RingtoneManager.TYPE_NOTIFICATION));
    }

    @Override
    public void onActivityResult(int requestCode, int responseCode, Intent data) {
	if (requestCode == DataConstants.VOLUME_SETTINGS_REQUEST_CODE) {
	    if (responseCode == RESULT_OK) {
		// String time = data.getStringExtra("time");
		// String note = data.getStringExtra("notes");
		// TimeRecord record = new TimeRecord(time, note);
		// databaseHelper.saveTimeRecord(record);
		// adapter.changeCursor(databaseHelper.getTimeRecordList());

		// using TimeAdapterUsingBaseAdapter
		// adapter.addItem(new TimeRecord(time, note));
		// adapter.notifyDataSetChanged();
	    }

	}
    }
}
